﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using _MetalSlug.Weapons.Units;
using _MetalSlug.Weapons.Factory;

namespace _MetalSlug.MyCharacters.Characters.Guns
{
    public class ShotGun : Gun
    {
        public const int CountBulletCanFire = 3;

        Vector2 Distance;
        Random Rad;

        public ShotGun()
        {
            typeOfGun = TYPE.SHOTGUN;
            countBullet = 99;
            Rad = new Random();
            Distance = new Vector2(70,70);
        }

        public override List<Bullet> Fire(Vector2 TopLeft, Vector2 Direction)
        {
            List<Bullet> lstFiredBullet = new List<Bullet>();
            int BulletCanFire = Math.Min(CountBullet, CountBulletCanFire);
            Vector2 StartPos = TopLeft;
            for (int i = 0; i < BulletCanFire; i++)
            {
                countBullet--;
                if (Direction == -Vector2.UnitY)
                {
                    StartPos = TopLeft + new Vector2(Rad.Next(-5, 25), 0);
                    StartPos.Y -= Distance.Y * i;
                }
                else
                {
                    StartPos = TopLeft + new Vector2(0, Rad.Next(50, 75));
                    StartPos.X += Distance.X * i;
                }

                Bullet bullet = BulletStore.GetInstance().Produce(Bullet.TYPE_BULLET.SHOTGUN_BULLET);
                bullet.Fire(StartPos, Direction);
                lstFiredBullet.Add(bullet);
            }

            if (!GameUtil.Audio.IsMuting)
            {
                GameUtil.Audio.ShotShotGun.Play();
            }

            return lstFiredBullet;
        }

        public override void AddBullet(int ExtraBullet)
        {
            countBullet += ExtraBullet;
        }

        public override Gun Clone()
        {
            Gun gun = new ShotGun();
            gun.Copy(this);
            return gun;
        }
    }
}
